/**
 * 需求汇总接口
 */

import { get, post } from '@/request/http'
import store from '@/store'

const url = '/FTKJWLHYPT/demandSummary/'

/**
 * 标书列表查询
 * @param {*} data
 */
export const bidList = data =>
  post(url + 'queryBid', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidCode: data.bidCode,
          bidStatus: data.bidStatus,
          bidFltId: store.state.user.FLT_UUID_DX_H,
          bidDptId: store.state.user.DPTID_DX_H,
          source: data.source
        }
      },
      PageIndex: {
        FTKJWLHYPT: data.pageIndex
      },
      PageSize: {
        FTKJWLHYPT: data.pageSize
      }
    }
  })

export const bidListDetail = data =>
  post(url + 'queryBidDetail', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId
        }
      }
    }
  })

/**
 * 原始需求查询
 * @param {*} data
 */
export const queryDemand = data =>
  post(url + 'queryDemand', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId,
          status: data.status,
          demandCode: data.code,
          site: data.site,
          destination: data.destination,
          checked: data.checked,
          sugarDptId: data.sugarDptId, // 集团id
          dptId: data.dptId, // 糖厂id
          transportMode: data.transportMode,
          product: data.product,
          kind: data.kind,
          dptPredptId: data.dptPredptId,
          submitEndTime: data.submitEndTime,
          submitStartTime: data.submitStartTime,
          tranType: data.tranType,
          source: data.source,
          ids:data.ids
        }
      },
      PageIndex: {
        FTKJWLHYPT: data.pageIndex
      },
      PageSize: {
        FTKJWLHYPT: data.pageSize
      }
    }
  })

/**
 * 招标信息删除
 * @param {*} data
 */
export const delBid = data =>
  post(url + 'delBid', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId,
          source: data.source
        }
      }
    }
  })

/**
 * 生成招标信息
 * @param {*} data
 */
export const addBid = data =>
  post(url + 'addBid', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          checked: data.from.checked,
          source: data.from.source,
          bidCode: data.from.bidCode,
          bidType: data.from.bidType,
          bidName: data.from.bidName,
          bidAmount: data.from.bidAmount,
          bidQuotations: data.from.bidQuotations,
          bidRange: data.from.bidRange,
          bidRemark: data.from.bidRemark,
          demandDTOS: data.demandDTOS,
          bidPlatformTogether: data.from.bidPlatformTogether,
          bidFltId: store.state.user.FLT_UUID_DX_H,
          bidCreator: store.state.user.USR_CODE_DX_H,
          bidDptId: store.state.user.DPTID_DX_H,
          bidOfferStart: data.from.bidOfferStart,
          bidOfferEnd: data.from.bidOfferEnd,
          bidStatus: data.from.bidStatus
        }
      }
    }
  })

/**
 * 招标信息发布,取消发布
 * @param {*} data
 */
export const updateBid = data =>
  post(url + 'updateBid', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId,
          bidStatus: data.bidStatus,
          bidType: data.bidType,
          bidAmount: data.bidAmount,
          bidName: data.bidName,
          bidQuotations: data.bidQuotations,
          bidRange: data.bidRange,
          bidRemark: data.bidRemark,
          bidEditor: store.state.user.USR_CODE_DX_H,
          demandDTOS: data.demandDTOS,
          bidPlatformTogether: data.bidPlatformTogether,
          bidOfferStart: data.bidOfferStart,
          bidOfferEnd: data.bidOfferEnd,
          source: data.source
        }
      }
    }
  })

/**
 * 下拉框查询
 * @param {*} data
 */
export const bidDropDown = data =>
  post('/FTKJWLHYPT/dropDown/getRefCodes', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          rvDomain: data.name,
          rvEdicode: data.rvEdicode
        }
      }
    }
  })

export const genBidCode = () => get(url + 'genBidCode')

export const queryDemandLine = data =>
  post(url + 'queryDemandLine', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          sugarId: data.sugarId
        }
      }
    }
  })

export const queryHistory = data =>
  post(url + 'refuseHis', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          demandCode: data.demandCode
        }
      }
    }
  })

export const refuseDemand = data =>
  post(url + 'refuseDemand', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          creator: store.state.user.USR_CODE_DX_H,
          fltUuid: store.state.user.FLT_UUID_DX_H,
          sugarDptId: store.state.user.DPTID_DX_H,
          demandCode: data.demandCode, // 需求编号
          sfdRefuseMsg: data.sfdRefuseMsg,
          sfdRefuseP: store.state.user.USR_CODE_DX_H,
          status: data.status,
          sugarId: data.sugarId
        }
      }
    }
  })
//品种类型
export const kindType = data => {
  return post('/FTKJWLHYPT/dropDown/getVarietiesDefaultDropDown', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          fltId: store.state.user.FLT_UUID_DX_H,
          preDptId: data.preDptId,
          dptId: data.dptId,
          isp: data.isp
        }
      }
    }
  })
}

//品种类型
export const productType = () => {
  return post('/FTKJWLHYPT/base/getRefCodesByType', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          rvDomain: '产品大类',
          rvTerId: store.state.user.FLT_UUID_DX_H
        }
      }
    }
  })
}
//糖厂类型
export const sugarType = data => {
  return post('/FTKJWLHYPT/system/querySysDepartmentList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          dptPredptId: data.dptPredptId,
          dptType: data.dptType,
          dptId: data.dptId
        }
      }
    }
  })
}
export const genBidName = () =>
  post(url + 'genBidName', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidDptId: store.state.user.DPTID_DX_H,
          bidFltId: store.state.user.FLT_UUID_DX_H
        }
      }
    }
  })

export const querySugarFactoryList = data =>
  post(url + 'querySugarFactoryList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId: data.bidId
        }
      }
    }
  })

/**
 * 批量提交
 * @param {*} data
 */
export const updateBidBatch = data =>
  post(url + 'updateBidBatch', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          list: data.list
        }
      }
    }
  })

/**
 * 需求确认
 * @param {*} data
 */
export const confirmDemand = data =>
  post(url + 'confirmDemand', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidEditor: store.state.user.USR_CODE_DX_H,
          bidStatus: data.status,
          demandDTOS: data.list
        }
      }
    }
  })

/**
 * 需求确认界面查询
 * @param {*} data
 */
export const queryConfirmDemand = data =>
  post(url + 'queryConfirmDemand', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          sugarId: data.sugarId,
          fltUuid: store.state.user.FLT_UUID_DX_H,
          sugarDptId: store.state.user.DPTID_DX_H,
          demandCode: data.demandCode,
          status: data.status,
          transportType: data.transportType,
          transportMode: data.transportMode,
          kind: data.kind,
          dptId: data.dptId,
          startTime: data.startTime,
          endTime: data.endTime
        }
      },
      PageIndex: {
        FTKJWLHYPT: data.index
      },
      PageSize: {
        FTKJWLHYPT: data.size
      }
    }
  })
